package dame2;

import java.util.Stack;

public class Stackqueue {            //用栈实现队列
    public Stack<Integer> stck1;
    public Stack<Integer> stck2;
    public Stackqueue() {
        stck1 = new Stack<>();
        stck2  =new Stack<>();
    }

    public void push(int x) {
        stck1.push(x);
    }

    public int pop() {
        if(empty()){
            return-1;
        }
        if(stck2.isEmpty()){
            while(!stck1.isEmpty()){
                stck2.push(stck1.pop());
            }
        }
        return stck2.pop();
    }


    public int peek() {
        if(empty()){
            return-1;
        }
        if(stck2.isEmpty()){
            while(!stck1.isEmpty()){
                stck2.push(stck1.pop());
            }
        }
        return stck2.peek();
    }

    public boolean empty() {
        return stck1.isEmpty()&&stck2.isEmpty();
    }
}
